angular.module('happyLive.controller', [])
    .controller('happyLiveListController', ['$scope', '$charitySocietyService','$stateParams', function ($scope, $charitySocietyService,$stateParams) {

        $scope.selectedType = 14;

        $scope.pageNumber = 0;

        $scope.selectYear = function(year){
            if($scope.selectedYear == year){
                return;
            }
            $scope.selectedYear = year;
            $scope.queryArticles();
        }

        $scope.articles = [];
        $scope.queryArticles = function () {
            $charitySocietyService.getArticles({
                pageNo: $scope.pageNumber,
                articleType: $scope.selectedType,
                numPerPage: 10,
            }, function (data) {
                if (null != data && data.data && data.data.length > 0) {
                    $scope.articles = $scope.articles.concat(data.data);
                }
            }, function (err) {
                console.error(err);
            });
        };

        $scope.loadMore = function () {
            $scope.pageNumber++;
            $scope.queryArticles($scope.selectedType);
        }

        $scope.getStyle = function(typeArray){
            console.log('here');
            for(var i = 0;i<typeArray.length; ++ i){
                if( $scope.selectedType == typeArray[i] ){
                    return {
                        "background":"#95B5E6"
                    }
                }
            }

            return {
                "background":"#777777"
            }

        }
        $scope.queryArticles($scope.selectedType);
    }]);